home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / qbsub10.arc / SIMTIME.SUB < prev    next >
Text File  |  1986-06-24  |  2KB  |  55 lines

  1. ' SIMTIME.SUB -- MSDOS QuickBASIC time simulation utility     25 June 86
  2. '        by David L. Poskie     (608) 274-9560
  3. '                  7118 Raymond Rd. Madison, WI 53719
  4. ' Please run any suggestions, corrections, additions, or changes by me.
  5. ' I can be messaged on all the major Madison, WI RBBS's.
  6.  
  7. SIMTIME:
  8.   '| Calculate simulated time/date subroutine based on real time clock
  9.   '| (1 second real time = 1 hour simulated time)
  10.   '|
  11.   '| To use:  BaseLine = TIMER (Sets BaseLine)
  12.   '|           Year = 1944      (Set year to 1944 or to your preference)
  13.   '|           Month = 6        (Set month to 6 [June] or to your preference)
  14.   '|          Day = 6          (Set day to 6 or to your preference)
  15.   '|          Hour = 4           (Set hour to 0400 or to your preference)
  16.   '| This would place you ready for a dawn landing on the beach
  17.   '|  at Normandy, on D-Day -- 6 June 1944 !
  18.   '|
  19.   '| Thereafter, any call to SIMTIME would give you a simulated time based
  20.   '|  on your original settings, at the rate of 1 hour elapsed simulated
  21.   '|  time for every second of elapsed real time. These subroutines are easy
  22.   '|  to modify for different scales; e.g. 1 sec real time = 1 min sim time.
  23.   
  24.      ' Slice is the difference since last adjustment to BaseLine
  25.     Slice = TIMER - BaseLine
  26.     BaseLine = TIMER        ' Reset BaseLine to current TIMER
  27.     ' First pass on adjusting the variables
  28.     WHILE Slice > 8640         ' 8640 hours = 1 year 
  29.           Slice  =  Slice - 8640    ' 24 hours * 30 days * 12 months = 8640
  30.           Year = Year + 1
  31.     WEND
  32.     WHILE Slice > 720        ' 720 hours = 1 month     
  33.           Slice  =  Slice - 720     ' There's only 30-day months here
  34.           Month = Month + 1        ' 24 hours * 30 days = 720
  35.     WEND
  36.     WHILE Slice > 24        ' 24 hours = 1 day 
  37.           Slice  =  Slice - 24
  38.           Day = Day + 1
  39.     WEND
  40.     Hour  =  Hour + Slice        ' What's left
  41.     ' Now, the only problem we may face is the case where Hour is > 24.
  42.     '   If it is, it may require a full chain of recalculation:
  43.     ' Second pass reconciles what's left
  44.     IF Hour > 24                            _
  45.        THEN Day = Day + 1 :                        _
  46.         Hour = Hour - 24    ' Add a day and drop 24 hours
  47.     IF Day > 30                            _
  48.        THEN Month = Month + 1 :                    _
  49.         Day = Day - 30        ' Add a month and drop 30 days
  50.     IF Month > 12                            _
  51.        THEN Year = Year + 1 :                    _
  52.         Month = Month - 12     'Add a year and drop 12 months
  53. RETURN
  54. ' >>>>> Physical EOF SIMTIME.SUB  25 June 86
  55.